package LC;

import java.util.PriorityQueue;

/**
 * @ClassName SmallLestK
 * @Description: TODO
 * @Author hl
 * @Date 2020/6/12
 * @Version V1.0
 **/
public class SmallLestK {
    public int[] smallestK(int[] arr, int k) {
        PriorityQueue<Integer> list=new PriorityQueue<>();
        int []result=new int[k];
        int j=0;
        for(int i=0;i<arr.length;i++){
            list.add(arr[i]);
            if(list.size()>(arr.length-k)){
               result[j++]=list.poll();
            }
        }
        return  result;
    }
}
